package com.cjq.config;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class DefaultConfig {

    @Bean
    public OkHttpClient okHttpClient() {
        return new OkHttpClient.Builder()
                // 连接超时
                .connectTimeout(5, TimeUnit.SECONDS)
                // 读取超时
                .readTimeout(10, TimeUnit.SECONDS)
                // 写入超时
                .writeTimeout(10, TimeUnit.SECONDS)
                // 连接保活间隔
                .pingInterval(30, TimeUnit.SECONDS)
                .connectionPool(new ConnectionPool(
                        // 最大空闲连接数
                        100,
                        // 连接存活时间
                        5, TimeUnit.MINUTES))
                // 自动重连
                .retryOnConnectionFailure(true)
                .build();
    }

}